//implement GDomainObjTester
//andycai.sc@gmail.com

#include "GDomainObjTester.h"

#include <iostream>
using namespace std;

MessageDomain::MessageDomain(GDataReceiver* dataReceiver) : GDomainObject(dataReceiver)
{
}

MessageDomain::~MessageDomain()
{
}

void MessageDomain::setMessage(const string& message)
{
    m_message = message;
    cout << "message is: " << m_message << endl << endl;
    post(MSG_CHANGE, &m_message);
}

MessageReceiver::MessageReceiver()
{
}

MessageReceiver::~MessageReceiver()
{
}

void MessageReceiver::setMessageDomain(MessageDomain* meDomain)
{
    m_messageDomain = meDomain;
}

void MessageReceiver::process(GDomainEvent* dEvent, GDomainObject* dObject)
{
    if (m_messageDomain == dObject)
    {
        if (dEvent->getEvent() == (long)MessageDomain::MSG_CHANGE)
        {
            const string& message = *((string*)dEvent->getData());
            cout << "==================================" << endl;
            cout << "=\n=\t" << message << "\n=" << endl;
            cout << "==================================" << endl;
        }
    }
}

GDomainObjTester::GDomainObjTester(const string& testName) : GFrameTester(testName)
{
}

GDomainObjTester::~GDomainObjTester()
{
}

void GDomainObjTester::run()
{
    MessageReceiver msgReceiver;
    MessageDomain msgDomain(&msgReceiver);

    msgReceiver.setMessageDomain(&msgDomain);
    msgDomain.setMessage("hello, I'm a domain object");
}
